package weaver.interfaces.shengxu.duss.action;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.shengxu.duss.utils.U9Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2024-06-05
 * @Description: 供应商准人申请流程流程调用U9客户创建接口
 * @ModifyLog:
 **/
public class WeaGyszrsqlcAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        String src = requestInfo.getRequestManager().getSrc();
        writeLog(">>>>>WeaGyszrsqlcAction>>>>>requestid=" + requestid);
        try {
            JSONArray paramsList = new JSONArray();
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            U9Util u9Util = new U9Util();
            rs.executeQuery("select * from " + tablename + " where requestid=?", requestid);
            rs.next();
            String bm = Util.null2String(rs.getString("bm"));
            String mc = Util.null2String(rs.getString("mc"));
            String jc = Util.null2String(rs.getString("jc"));
            String lxr = Util.null2String(rs.getString("lxr"));
            String lxdh = Util.null2String(rs.getString("lxdh"));
            String yx = Util.null2String(rs.getString("yx"));
            String dz = Util.null2String(rs.getString("dz"));
            String gsh = Util.null2String(rs.getString("gsh"));
            String shengxrq = Util.null2String(rs.getString("shengxrq"));
            String sxrq = Util.null2String(rs.getString("sxrq"));
            String fldanhang = Util.null2String(rs.getString("fldanhang"));
            String jybzdx = Util.null2String(rs.getString("jybzdx"));
            String skbzdx = Util.null2String(rs.getString("skbzdx"));
            String szhdx = Util.null2String(rs.getString("szhdx"));
            JSONObject paramsJson = new JSONObject();
            JSONObject contextdtoJson = new JSONObject();
            contextdtoJson.put("EntCode", baseBean.getPropValue("u9", "entcode"));
            contextdtoJson.put("OrgCode", baseBean.getPropValue("u9", "orgcode"));
            contextdtoJson.put("UserCode", baseBean.getPropValue("u9", "userCode"));
            paramsJson.put("ContextDTO", contextdtoJson);
            paramsJson.put("OtherID", baseBean.getPropValue("u9", "clientId"));
            paramsJson.put("Code", bm);
            paramsJson.put("Name", mc);
            paramsJson.put("ShortName", jc);
            paramsJson.put("StateTaxNo", gsh);
            JSONObject effectiveJson = new JSONObject();
            effectiveJson.put("IsEffective", true);
            effectiveJson.put("EffectiveDate", shengxrq);
            effectiveJson.put("DisableDate", sxrq);
            paramsJson.put("Effective", effectiveJson);
            JSONObject categoryJson = new JSONObject();
            categoryJson.put("Code", fldanhang);
            paramsJson.put("Category", categoryJson);
            JSONObject tradecurrencyJson = new JSONObject();
            tradecurrencyJson.put("Code", jybzdx);
            paramsJson.put("TradeCurrency", tradecurrencyJson);
            JSONObject checkcurrencyJson = new JSONObject();
            checkcurrencyJson.put("Code", skbzdx);
            paramsJson.put("CheckCurrency", checkcurrencyJson);
            JSONObject taxscheduleJson = new JSONObject();
            taxscheduleJson.put("Code", szhdx);
            paramsJson.put("TaxSchedule", taxscheduleJson);
            JSONObject descFlexFieldJson = new JSONObject();
            descFlexFieldJson.put("m_privateDescSeg1", lxr);
            descFlexFieldJson.put("m_privateDescSeg2", lxdh);
            descFlexFieldJson.put("m_privateDescSeg3", dz);
            descFlexFieldJson.put("m_privateDescSeg4", yx);
            paramsJson.put("DescFlexField", descFlexFieldJson);
            paramsList.add(paramsJson);
            baseBean.writeLog(">>>>>WeaGyszrsqlcAction>>>>>paramsList=" + paramsList);
            JSONObject resultJson = u9Util.CreateSupplier(paramsList, requestid, src);
            baseBean.writeLog(">>>>>WeaGyszrsqlcAction>>>>>resultJson=" + resultJson);
            String code = Util.null2String(resultJson.getString("code"));
            String message = Util.null2String(resultJson.getString("message"));
            if ("success".equals(code)) {
                String data = Util.null2String(resultJson.getString("data"));
                rs.executeUpdate("update " + tablename + " set gysid=? where requestid=?", data, requestid);
                return Action.SUCCESS;
            }
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("调用U9系统接口返回:" + message);
            return Action.FAILURE_AND_CONTINUE;
        } catch (Exception e) {
            writeLog(">>>>>WeaGyszrsqlcAction>>>>>Exception=" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口处理异常,请联系管理员");
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}